﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;

namespace Ewts.BaseData
{
    public partial class MaterialPriceModify : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(id);
                }
            }
        }

        private void ShowInfo(int id)
        {
            DataLib.BLL.MaterialPrice bll = new DataLib.BLL.MaterialPrice();
            DataLib.Model.MaterialPrice model = bll.GetModel(id);
            this.lblid.Text = model.id.ToString();
            this.txtmaterialid.Text = model.materialid.ToString();
            this.txtRMBPrice.Text = model.RMBPrice.ToString();
            this.txtUSPrice.Text = model.USPrice.ToString();
            this.txtSGDPrice.Text = model.SGDPrice.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (txtmaterialid.Text.Trim().Length == 0)
            {
                strErr += "原料名称不能为空！\\n";
            } if (!PageValidate.IsNumber(txtRMBPrice.Text) && !PageValidate.IsNumber(txtUSPrice.Text) && !PageValidate.IsNumber(txtSGDPrice.Text))
            {
                strErr += "人民币价格、美金价格、新币价格至少一个不为空且必须为数字！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }

            int id = int.Parse(this.lblid.Text);
            int materialid = int.Parse(this.txtmaterialid.Text);
            decimal RMBPrice = decimal.Parse(this.txtRMBPrice.Text);
            decimal USPrice = decimal.Parse(this.txtUSPrice.Text);
            decimal SGDPrice = decimal.Parse(this.txtSGDPrice.Text);


            DataLib.Model.MaterialPrice model = new DataLib.Model.MaterialPrice();
            model.id = id;
            model.materialid = materialid;
            model.RMBPrice = RMBPrice;
            model.USPrice = USPrice;
            model.SGDPrice = SGDPrice;

            DataLib.BLL.MaterialPrice bll = new DataLib.BLL.MaterialPrice();
            bll.Update(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "MaterialPriceList.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("MaterialPriceList.aspx");
        }
    }
}
